<!--
 * @轮子的作者: 轮子哥
 * @Date: 2023-10-13 10:45:04
 * @LastEditTime: 2023-11-14 17:38:16
-->
<template>
    <div class="leftMain">
        <div class="ss1">{{ $t('text.router.l40') }}</div>
        <div class="leftTop2" v-for="item in jobList" v-bind:key="item">
            <div class="df" @click="setPage(item)" :class="item.name == selectPageData.name ? 'blueBg' : ''">
                <img class="img2" src="../../assets/images/icon.png" />
                <div class="items">{{ item.name }}</div>
            </div>
        </div>
    </div>

    <div class="rightMain">
        <div class="title" v-if="nextItemClick1">{{ selectPageData.name }}</div>

        <div class="sss6" v-if="nextItemClick1">
            <div class="ss12">
                <div class="ss11" v-for="item in selectPageEmployee.filter(v => v.def === '1')" v-bind:key="item"
                    @click="nextItemClick1 = !nextItemClick1; selectEmployeeDetail = item; isDefaultJobClick = true"
                    style="border: none;">
                    <div class="ss8">{{ $t('text.System.l284') }}</div>
                    <div class="ss10">{{ item.sumPrice }}&ensp;></div>
                </div>
            </div>
        </div>

        <div class="ss6" v-if="nextItemClick1">
            <div class="ss5">{{ $t('text.System.l285') }}</div>
            <div class="ss12" v-if="selectPageEmployee.filter(v => v.def !== '1').length > 0">
                <div class="ss11" v-for="item in selectPageEmployee.filter(v => v.def !== '1')" v-bind:key="item"
                    @click="nextItemClick1 = !nextItemClick1; selectEmployeeDetail = item; isDefaultJobClick = false">
                    <div class="ss8">{{ item.name }}</div>
                    <div class="ss10">{{ item.sumPrice }}&ensp;></div>
                </div>
            </div>
            <div v-else class="ss12">
                {{ $t('text.System.l305') }}
            </div>
        </div>

        <div class="title2" v-if="!nextItemClick1">
            <div @click="nextItemClick1 = !nextItemClick1" class="backDiv">
                <img class="backImg" src="../../assets/images/back.svg">
                <div style="padding-top: 2px;">{{ $t('text.System.l25') }}</div>
            </div>
            <div style="flex: 1;">{{ isDefaultJobClick?$t('text.System.l286'):$t('text.System.l287') }}</div>
            <div style="flex: 1;"></div>
        </div>


        <div class="ss6" v-if="!nextItemClick1">
            <!--固定薪资-->
            <div class="ss12" style="background: #eee;border-radius: 5px;">
                <div class="ss11" style="border: none;">
                    <div class="ss8">{{ $t('text.System.l288') }}</div>
                    <div class="ss10">{{ selectEmployeeDetail.name }}</div>
                </div>
            </div>
            <div class="ss5">{{ $t('text.System.l289') }}</div>
            <div class="ss12">
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l290') }}</div>
                    <div class="ss10">
                        <CommonInput leftText="AED" :inputStyle="inputStyle" :isNumber="2"
                            :value="selectEmployeeDetail.basicPrice" ref="basicPrice"
                            @blurReturn="setValue($event, selectEmployeeDetail.basicPrice, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'basicPrice')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l291') }}</div>
                    <div class="ss10">
                        <CommonInput leftText="AED" :inputStyle="inputStyle" :isNumber="2"
                            :value="selectEmployeeDetail.jobPrice" ref="jobPrice"
                            @blurReturn="setValue($event, selectEmployeeDetail.jobPrice, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'jobPrice')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l292') }}</div>
                    <div class="ss10">
                        <CommonInput leftText="AED" :inputStyle="inputStyle" :isNumber="2"
                            :value="selectEmployeeDetail.trafficPrice" ref="trafficPrice"
                            @blurReturn="setValue($event, selectEmployeeDetail.trafficPrice, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'trafficPrice')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l293') }}</div>
                    <div class="ss10">
                        <CommonInput leftText="AED" :inputStyle="inputStyle" :isNumber="2"
                            :value="selectEmployeeDetail.phonePrice" ref="phonePrice"
                            @blurReturn="setValue($event, selectEmployeeDetail.phonePrice, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'phonePrice')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l294') }}</div>
                    <div class="ss10">
                        <CommonInput leftText="AED" :inputStyle="inputStyle" :isNumber="2"
                            :value="selectEmployeeDetail.mealPrice" ref="mealPrice"
                            @blurReturn="setValue($event, selectEmployeeDetail.mealPrice, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'mealPrice')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l295') }}</div>
                    <div class="ss10">
                        <CommonInput leftText="AED" :inputStyle="inputStyle" :isNumber="2"
                            :value="selectEmployeeDetail.secrecyPrice" ref="secrecyPrice"
                            @blurReturn="setValue($event, selectEmployeeDetail.secrecyPrice, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'secrecyPrice')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l296') }}</div>
                    <div class="ss10">
                        <CommonInput leftText="AED" :inputStyle="inputStyle" :isNumber="2"
                            :value="selectEmployeeDetail.otherPrice" ref="otherPrice"
                            @blurReturn="setValue($event, selectEmployeeDetail.otherPrice, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'otherPrice')">
                        </CommonInput>
                    </div>
                </div>
            </div>

            <!--考勤扣款-->
            <div class="ss5">{{ $t('text.System.l297') }}</div>
            <div class="ss12">
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l298') }}</div>
                    <div class="ss10">
                        <CommonInput :leftText="$t('text.System.l303')" :inputStyle="inputStyle2" :isNumber="2"
                            :value="selectEmployeeDetail.lateAttend" ref="lateAttend"
                            @blurReturn="setValue($event, selectEmployeeDetail.lateAttend, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'lateAttend')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l299') }}</div>
                    <div class="ss10">
                        <CommonInput :leftText="$t('text.System.l303')" :inputStyle="inputStyle2" :isNumber="2"
                            :value="selectEmployeeDetail.quitAttend" ref="quitAttend"
                            @blurReturn="setValue($event, selectEmployeeDetail.quitAttend, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'quitAttend')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l300') }}</div>
                    <div class="ss10">
                        <CommonInput :leftText="$t('text.System.l303')" :inputStyle="inputStyle2" :isNumber="2"
                            :value="selectEmployeeDetail.lackAttend" ref="lackAttend"
                            @blurReturn="setValue($event, selectEmployeeDetail.lackAttend, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'lackAttend')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l301') }}</div>
                    <div class="ss10">
                        <CommonInput :leftText="$t('text.System.l303')" :inputStyle="inputStyle2" :isNumber="2"
                            :value="selectEmployeeDetail.absentAttend" ref="absentAttend"
                            @blurReturn="setValue($event, selectEmployeeDetail.absentAttend, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'absentAttend')">
                        </CommonInput>
                    </div>
                </div>
                <div class="ss11">
                    <div class="ss8">{{ $t('text.System.l302') }}</div>
                    <div class="ss10">
                        <CommonInput :leftText="$t('text.System.l303')" :inputStyle="inputStyle2" :isNumber="2"
                            :value="selectEmployeeDetail.leaveAttend" ref="leaveAttend"
                            @blurReturn="setValue($event, selectEmployeeDetail.leaveAttend, selectEmployeeDetail.id, selectEmployeeDetail.jobId, 'leaveAttend')">
                        </CommonInput>
                    </div>
                </div>
            </div>
        </div>


    </div>
</template>
    
<script>
import { ElMessage } from 'element-plus'
import CommonInput from '@/components/input/CommonInput.vue'
import { jobList, salaryConfigFindPage, salaryConfigUpdate } from '../../http/api'
export default {
    name: "SalaryConfiguration",
    components: {
        CommonInput
    },
    data() {
        return {
            jobList: [],
            selectPageData: {},
            selectPageEmployee: [],
            selectEmployeeDetail: {},
            inputStyle: { border: 'none', textAlign: 'right', margin: 0, paddingRight: '55px' },
            inputStyle2: { border: 'none', textAlign: 'right', margin: 0, paddingRight: '75px' },
            pageNo: 1,
            total: 0,
            isDefaultJobClick: false,
            nextItemClick1: true,
            nextItemClick2: false,
        }
    },
    mounted() {
        this.init()
    },
    methods: {

        init() {
            jobList().then(res => {
                if (res !== undefined) {
                    this.jobList = res
                    if (res.length > 0) {
                        this.selectPageData = res[0]
                        this.getEmployee()
                    }
                }
            }).catch()
        },

        setPage(item) {
            this.selectPageData = item
            this.getEmployee()
        },
        getEmployee() {
            salaryConfigFindPage({ jobId: this.selectPageData.id}).then(res => {
                if (res !== undefined) {
                    this.total = res.total
                    this.selectPageEmployee = res.dataList
                }
            }).catch()
        },
        setValue(value, oldValue, id, jobId, key) {
            if (value != oldValue) {

                salaryConfigUpdate({ id: id, jobId: jobId, [key]: value }).then(res => {
                    if (res !== undefined) {
                        this.selectEmployeeDetail[key] = value
                        ElMessage.success(this.$t('text.System.l37'))
                        this.getEmployee()
                    }
                    else {
                        this.selectEmployeeDetail[key] = oldValue
                        this.$refs[key].resetDefault()
                    }
                }).catch()
            }
            console.log(value, oldValue, id, key)
        }
    },
    watch: {},
    computed: {
    },
}
</script>
    
<style scoped>
input {
    border: none;
    outline: none;
    text-align: end;
}

textarea {
    width: 100%;
    border: none;
    outline: none;
}


.ss1 {
    color: #6698ff;
    font-size: 17px;
    text-align: left;
}

.leftMain {
    min-width: 310px;
    padding: 0 10px;
    border-right: solid 1px var(--el-menu-border-color);
    overflow: auto;
    margin: 10px 0;
}

.leftTop2 {
    border: 1px solid #cecece;
    border-radius: 5px;
    margin-top: 10px;
    position: relative;
    color: gray;
}

.df {
    display: flex;
    align-items: center;
    padding: 6px 10px;
}

.img2 {
    width: 22px;
    height: 22px;
}

.items {
    margin-left: 15px;
    font-size: 12px;
    width: 100%;
    text-align: left;
}

.blueBg {
    background: #6698ff;
    color: white;
}

.backDiv {
    display: flex;
    flex: 1 1 0%;
    color: #6698ff;
    font-size: 13px;
    align-items: center;
    padding-left: 20px;
}

.backImg {
    width: 23px;
    height: 23px;
    padding-right: 5px;
}

.ss12 {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid #eee;
    padding: 7px 10px;
    color: gray;
    font-size: 12px;
    margin-bottom: 15px;
}

.ss11 {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    padding: 7px 10px;
    color: gray;
    font-size: 12px;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: none;
}

input {
    border: none;
    outline: none;
    text-align: end;
}

textarea {
    width: 100%;
    border: none;
    outline: none;
}

.title {
    background: #f2f2f2;
    color: gray;
    height: 40px;
    line-height: 40px;
}

.title2 {
    background: #f2f2f2;
    color: gray;
    height: 40px;
    line-height: 40px;
    display: flex;
}

.rightMain {
    width: 100%;
    margin: 10px 15px;
    border: 1px solid #eee;
    display: flex;
    flex-direction: column;
    margin-right: 20px;
}

.ss7 {
    display: flex;
    justify-content: space-between;
    border: 1px solid #eee;
    padding: 7px 10px;
    color: gray;
    font-size: 12px;
    margin-bottom: 15px;
}

.ss6 {
    display: flex;
    padding: 7px 10px;
    color: gray;
    font-size: 12px;
    flex-direction: column;
    min-width: 300px;
    padding: 30px 100px;
    overflow: auto;
    height: 100%;
    padding-top: 10px;
}

.sss6 {
    display: flex;
    padding: 7px 10px;
    color: gray;
    font-size: 12px;
    flex-direction: column;
    min-width: 300px;
    padding: 0px 100px;
    padding-top: 30px;
}

.ss5 {
    text-align: left;
    color: #444;
    padding: 7px 0px;
    font-size: 13px;
}

</style>